package com.wpfly.SpringBootDemo.entity;

import lombok.Data;
import lombok.ToString;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
@Entity
@Table(name="sbd_teacher")
@EntityListeners(AuditingEntityListener.class)
public class Teacher implements Serializable {

    @Column(name="id",nullable=false,length=11)
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Id
    private Long id;//唯一id

    @Column(name="createtime",columnDefinition = "datetime NOT NULL DEFAULT CURRENT_TIMESTAMP")
    @CreatedDate
    private Date createTime;//创建时间

    @Column(name="updatetime",columnDefinition = "datetime NOT NULL DEFAULT CURRENT_TIMESTAMP")
    @LastModifiedDate
    private Date updateTime;//更新时间

    @Column(name="name",length=20)
    private String name;

    @ToString.Exclude
    @ManyToMany(mappedBy="teachers")
    private List<Student> students = new ArrayList<>();
}
